package com.lul15834.orderfood.activity.user.fragment;


import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ListView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lul15834.orderfood.R;

import com.lul15834.orderfood.activity.user.adapter.BuyFoodAdapter;
import com.lul15834.orderfood.bean.FoodBean;

import com.lul15834.orderfood.dao.FoodDao;

import java.util.List;


public class UserBuyFragment extends Fragment {
    View rootview;//根视图
    private Context context;
    private String businessId;
    public UserBuyFragment(String businessId,Context context){
        this.businessId=businessId;
        this.context=context;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootview=inflater.inflate(R.layout.fragment_user_buy, container, false);
        //适配器
        RecyclerView listView=rootview.findViewById(R.id.user_buy_food_list);
        listView.setLayoutManager(new LinearLayoutManager(getContext()));
        //通过外面进行传参
        List<FoodBean> list= FoodDao.getAllFoodById(businessId);
        BuyFoodAdapter adapter=new BuyFoodAdapter(list,context);
        if (list==null||list.size()==0){
            listView.setAdapter(null);
        }else {
            listView.setAdapter(adapter);
        }
        return rootview;
    }


}